////////////////////////////////////////////////////////////
// Workfile : Testdriver.cpp
// Author : Andreas Lehner
// Date : 11.11.2012
// Description : testdriver for testing interfaces INortel and IEpcos
// Remarks : -
// Revision : 1
////////////////////////////////////////////////////////////
#include <iostream>
#include <list>
#include <cassert>
#include "IEpcos.h"
#include "INortel.h"
#include "Epcos.h"
#include "Nortel.h"

int main(){

	IEpcos *epcos = new Epcos();
	INortel *nortel = new Nortel();

	std::list<std::string> files;
	files.push_back("alphabet.txt");
	files.push_back("numbers.txt");
	files.push_back("symbols.txt");
	files.push_back("emptyfile.txt");
	
	// Encrypt with epcos, decrypt with nortel
	for (std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it) {
		epcos->EncryptRSA(*it);
		nortel->Decipher(INortel::eRSA, it->append(".RSA"));
	}

	// Get rid of the .RSA suffix
	files.clear();
	files.push_back("alphabet.txt");
	files.push_back("numbers.txt");
	files.push_back("symbols.txt");
	files.push_back("emptyfile.txt");

	// Encrypt with nortel, decrypt with epcos
	for (std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it) {
		nortel->Encipher(INortel::eRSA, *it);
		epcos->DecryptRSA(it->append(".RSA"));  // ".RSA" has already been appended
	}

	// Get rid of the .RSA suffix
	files.clear();
	files.push_back("alphabet.txt");
	files.push_back("numbers.txt");
	files.push_back("symbols.txt");
	files.push_back("emptyfile.txt");

	// encrypt and decrypt with nortel's Caesar algo
	for (std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it) {
		nortel->Encipher(INortel::eCaesar, *it);
		nortel->Decipher(INortel::eCaesar, it->append(".Caesar"));
	}

	//try empty filenames in epcos and nortel
	try{
		nortel->Encipher(INortel::eCaesar, "");
	}
	catch(char const* ex){
		assert(ex != 0);
		delete nortel; nortel = 0;
		std::cerr << ex << std::endl;
	}
	try{
		epcos->DecryptRSA("");
	}
	catch(char const* ex){
		assert(ex != 0);
		delete epcos; epcos = 0;
		std::cerr << ex << std::endl;
	}

	delete epcos; epcos = 0;
	delete nortel; nortel = 0;

	return 0;
}